package dry.example.disruptor2;

import com.lmax.disruptor.dsl.Disruptor;
import dry.example.disruptor.Message;
import dry.example.disruptor.Producer;

import java.util.concurrent.Executors;

/**
 * @author zc
 */
public class RunDemo {

    public static void main(String[] args) {
        //大小必须为2的幂
        Disruptor<Message> disruptor = new Disruptor<>(Message::new, 1024, Executors.defaultThreadFactory());
        Consumer c1 = new Consumer(1);
        Consumer c2 = new Consumer(2);
        Consumer c3 = new Consumer(3);
        //每条消息只会被消费1次
        disruptor.handleEventsWithWorkerPool(c1, c2, c3);
        disruptor.start();
        Producer producer = new Producer(disruptor);
        while (true) {
            try {
                producer.send(new Message("1001", "0000012650032", System.currentTimeMillis()));
                Thread.sleep(1000);
            } catch (Exception ignored) {

            }
        }
    }

}
